Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy should be supplied when refreshing the cache due to type mismatch #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ajbeaven
Copy link

I have been struggling to get LazyCache to behave when setting a SizeLimit in the underlying MemoryCache. Intermittently it seemed, it would throw the following exception despite me supplying a size with the cache entry:

InvalidOperationException: Cache entry must specify a value for Size when SizeLimit is set.

Looking at the code, it appears in the situation where you have a type mis-match, the cache is refreshed however the supplied policy is not passed through which was causing the exception to be thrown.

I'm somewhat surprised no one has faced this before so I'm 70% sure I'm doing something wrong here. Consider this a very tentative PR ;)

@alastairtree
Copy link
Owner

Thanks for this - looks like a genuine bug! Any chance you could add a unit tests that reproduces the issue so we don't make this mistake again?

@ajbeaven
Copy link
Author

ajbeaven commented May 10, 2021

I've added a couple of tests that should do the job. It doesn't test that associated extension methods use IAppCache.GetOrAdd<T>() (the method I cover in my tests) internally, but I assume this is covered elsewhere.

It'd look cleaner to use the GetOrAdd<T>() extension method that takes a TimeSpan, but it's probably safer to test this way. Let me know if you prefer aesthetics though, and I'll change it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants